#include "Mouse.h"

Mouse* Mouse::mInstance  = NULL;

Mouse* Mouse::Instance()
{
	if(mInstance == NULL)
	{
		mInstance = new Mouse();
	}
	return mInstance;
}

Mouse::Mouse()
{

}

Mouse::Mouse(const Mouse&)
{

}

Mouse::~Mouse()
{

}


void Mouse::Initialize(HWND hWnd, HINSTANCE hInstance)
{
	mHWnd = hWnd;

	if (DirectInput8Create(hInstance, DIRECTINPUT_VERSION,IID_IDirectInput8, (void**)&mDInput, NULL) != DI_OK)
	{
	}

	if (mDInput->CreateDevice(GUID_SysMouse, &mDIMouse, NULL) != DI_OK)
	{
	}

	if (mDIMouse->SetCooperativeLevel(hWnd, DISCL_NONEXCLUSIVE | DISCL_FOREGROUND) != DI_OK)
	{
	}

	if (mDIMouse->SetDataFormat(&c_dfDIMouse) != DI_OK)
	{
	}

	if (mDIMouse->Acquire() != DI_OK)
	{
	}
}


void Mouse::Update()
{
	RECT rect;
	GetWindowRect(mHWnd, &rect);
	SetCursorPos(rect.left+ 150,rect.top + 150);

	ZeroMemory( &mMouseState, sizeof(mMouseState) );
	mDIMouse->GetDeviceState( sizeof(DIMOUSESTATE), &mMouseState );
}

DIMOUSESTATE2 Mouse::getMouseState()
{
	return mMouseState;
}